package com.shunhe.shyqfk.ui;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.reflect.TypeToken;
import com.ruitu.arad.api.okhttp.Url;
import com.ruitu.arad.api.okhttp.response.JsonResponseHandler;
import com.ruitu.arad.base.BaseActivity;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.router_module.Logg;
import com.ruitu.router_module.util.AlertUtil;
import com.shunhe.shyqfk.R;
import com.shunhe.shyqfk.base.Gl;
import com.shunhe.shyqfk.model.DataStat;
import com.shunhe.shyqfk.model.OutQuery;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class DataStatActivity extends BaseActivity {
    TextView tv_enter, tv_out;
    RecyclerView rcv_list;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_data_stat;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tv_enter = findViewById(R.id.tv_enter);
        tv_out = findViewById(R.id.tv_out);
        rcv_list = findViewById(R.id.rcv_list);

        setHeadTitle("出入园区数据统计");

        setSelected(true, false);

    }

    private void setSelected(boolean sel1, boolean sel2) {
        tv_enter.setSelected(sel1);
        tv_out.setSelected(sel2);
    }

    // 根据扫码结果请求出出出园登记信息
    private void reqDataStat(String id) {
        Map<String, String> params = new HashMap<>();
        params.put("id", id);

        hideProgress();
        showProgress();
        Gl.okHttp.get().url(Url.OUT_QUERY).params(params)
                .tag(this).enqueue(this, new JsonResponseHandler() {
            @Override
            public void onFailure(int statusCode, String error_msg) {
                hideProgress();
                ToastUtils.showShort("请求失败");
                Logg.i("reqDataStat.error_msg = " + error_msg);
            }

            @Override
            public void onSuccess(int statusCode, JSONObject response) {
                hideProgress();
                String code = response.optString("code");
                String msg = response.optString("msg");
                String data = response.optString("data");
                Logg.i("reqDataStat.code = " + code + " msg = " + msg);
                Logg.i("reqDataStat.data = " + data);
                if (TextUtils.equals("1", code)) {
                    OutQuery out = Gl.gson.fromJson(data, new TypeToken<OutQuery>() {
                    }.getType());
                } else {
                    ToastUtils.showShort(msg);
                    AlertUtil.showComDialog2(DataStatActivity.this, msg, null);
                }
            }
        });
    }

    private class DataStatAdapter extends ListBaseAdapter<DataStat> {

        public DataStatAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_data_stat;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {

        }
    }

}